'use strict';

import * as actions from '../../actions/ring_tags';

// 对页面prop 数据进行管理
const initialState = {
  creating: false,
  error:false,
  loginError:false,
  message:"",
  curActive:false
};
const defaultAction = {
  type: 'doNothing'
}; 
export default function index(state = initialState, action = defaultAction) {
    switch (action.type) {
		case actions.LOAD_START:
			return Object.assign({}, state, {
				creating:true,
				error:false,
				loginError:false
			});
		break;
		case actions.LOAD_ERR:
			return Object.assign({}, state, {
				creating:false,
				error:true,
				loginError:action.loginFalse,
				message:action.message
			});
		break;
		case actions.CLOSE_DIALOG:
			return Object.assign({}, state, {
				error:action.visible,
				loginError:false
			});
		break;
		case actions.GET_TAG_TASK:
			return Object.assign({}, state, {
				creating:false,
				error:false,
				loginError:false,
				data:action.data,
				total:action.total
			});
		break;
		case actions.REMOVE_TAG_TASK:
			let dataKey;
			state.data.map((task,key)=>{
				if(task.task_id==action.task_id){
					dataKey=key;
				}
			});
			state.data.splice(dataKey,1);
			return Object.assign({}, state, {
				creating:false,
				error:false,
				loginError:false
			});
		break;
		default:
		return state;
	}
}